package no.ntnu.fp.gui;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import java.awt.event.WindowEvent;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import javax.naming.ldap.Rdn;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.event.ListDataEvent;
import javax.swing.event.ListDataListener;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.DefaultListCellRenderer;
import javax.swing.DefaultListModel;
import javax.swing.JComponent;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JTextArea;
import javax.swing.JRadioButton;
import javax.swing.ButtonGroup;
import javax.swing.JLabel;
import javax.swing.ListCellRenderer;
import javax.swing.ListModel;
import javax.swing.SpinnerDateModel;
import javax.swing.SpinnerModel;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

import no.ntnu.fp.client.ClientModelHandler;
import no.ntnu.fp.model.Appointment;
import no.ntnu.fp.model.Appointment.RSVP;
import no.ntnu.fp.model.Message.MessageType;
import no.ntnu.fp.model.Person;
import no.ntnu.fp.model.Room;

import org.jdesktop.swingx.JXDatePicker;
import javax.swing.JList;
import javax.swing.JSpinner;
import javax.swing.JComboBox;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import org.jdesktop.beansbinding.BeanProperty;
import org.jdesktop.beansbinding.AutoBinding;
import org.jdesktop.beansbinding.Bindings;
import org.jdesktop.beansbinding.Converter;
import org.jdesktop.beansbinding.AutoBinding.UpdateStrategy;
import org.jdesktop.el.impl.util.ReflectionUtil;

import java.sql.Time;
import javax.swing.border.LineBorder;

public class NewAppointmentWindow extends JDialog {
	public class DateConverter extends Converter<java.sql.Date, Date> {
		@Override
		public Date convertForward(java.sql.Date value) {
			return new Date(value.getTime());
		}

		@Override
		public java.sql.Date convertReverse(Date value) {
			return new java.sql.Date(value.getTime());
		}

	}

	private final class SelectedPeopleListCellRenderer extends
			DefaultListCellRenderer implements ListCellRenderer {
		@Override
		public Component getListCellRendererComponent(JList list, Object value,
				int index, boolean isSelected, boolean cellHasFocus) {
			JLabel label = (JLabel) super.getListCellRendererComponent(list,
					value, index, isSelected, cellHasFocus);
			Person p = (Person) value;
			if (p == null) {
				label.setText("Null");
			} else {
				label.setText(p.getName());
				if (model.inviteList.containsKey(p.id)) {
					RSVP rsvp = model.inviteList.get(p.id);
					if (rsvp != null) {
						label.setText(p.getName() + " (" + rsvp.getText() + ")");
					}
				}
			}
			return label;
		}
	}

	private final class SelectedEmployeesListModel extends DefaultListModel
			implements ListModel {
		List<Person> list = new ArrayList<Person>();
		private ListDataListener listener;

		public SelectedEmployeesListModel() {
			super();
			final Appointment m = model;
			for (Entry<Integer, RSVP> entry : model.inviteList.entrySet()) {
				Integer personId = entry.getKey();
				Person person = Person.get(personId);
				System.out.println("henter person #" + personId + " som er "
						+ person);
				// if (person != null)
				list.add(Person.get(personId));
			}
		}

		@Override
		public int getSize() {
			return list.size();
		}

		@Override
		public void addListDataListener(ListDataListener l) {
			this.listener = l;
			super.addListDataListener(l);

		}

		public void addPerson(Person p) {
			if (list.contains(p)) {
				JOptionPane.showMessageDialog(null, "Already invited");
			} else {
				list.add(p);
				listener.contentsChanged(new ListDataEvent(this,
						ListDataEvent.INTERVAL_ADDED, 0, list.size() - 1));
				findAppropriateRoom();
			}
		}

		public Person removePerson(int index) {
			listener.contentsChanged(new ListDataEvent(this,
					ListDataEvent.INTERVAL_REMOVED, index, index));
			return list.remove(index);
		}

		@Override
		public Object getElementAt(int index) {
			return list.get(index);
		}
	}

	private final class RoomListRenderer extends DefaultListCellRenderer
			implements ListCellRenderer {
		@Override
		public Component getListCellRendererComponent(JList list, Object value,
				int index, boolean isSelected, boolean cellHasFocus) {
			JLabel x = (JLabel) super.getListCellRendererComponent(list, value,
					index, isSelected, cellHasFocus);
			Room room = (Room) value;
			if (room == null) {
				x.setText("--no room selected, pelle--");
			} else {
				x.setText(room.getName() + " (" + room.getCapacity() + ")");
			}
			return x;
		}
	}

	private final class RoomSelectModel extends DefaultComboBoxModel implements
			ComboBoxModel {
		private static final long serialVersionUID = 1223936326638353293L;
		private Room selected;
		List<Room> list = new ArrayList<Room>();

		public RoomSelectModel(Room currentRoom) {
			super();
			list = Room.all();
			selected = currentRoom;
		}

		@Override
		public void removeListDataListener(ListDataListener arg0) {
		}

		@Override
		public int getSize() {
			return list.size();
		}

		@Override
		public Object getElementAt(int index) {
			return list.get(index);
		}

		@Override
		public void setSelectedItem(Object anItem) {
			selected = (Room) anItem;
		}

		@Override
		public Object getSelectedItem() {
			return selected;
		}
	}

	private final class TimeConverter extends Converter<Time, Object> {
		@Override
		public Time convertReverse(Object value) {
			return new Time(((Date) value).getTime());
		}

		@Override
		public Object convertForward(Time value) {
			return new Date(value.getTime());
		}
	}

	private static final long serialVersionUID = 1L;

	private final JPanel contentPanel = new JPanel();
	private JTextField txtTittel;
	private JRadioButton rdbtnJobb;
	private JRadioButton rdbtnPrivat;
	private final ButtonGroup buttonGroup = new ButtonGroup();
	private JLabel lblInterneDeltakere;
	private JLabel lblEksterneDeltakere;
	private JLabel lblVelgInterneDeltagere;
	private JLabel lblVelgRom;
	private JRadioButton rdbtnAutomatisk;
	private JRadioButton rdbtnManuell;
	private JLabel lblRom;
	private JComboBox roomSelectionBox;
	private JTextField searchField;
	private JTextField txtSted;
	private JTextField txtGuestCount;
	private JTextField externPeeps;
	private JList employeesJList;
	private final ButtonGroup buttonGroup_1 = new ButtonGroup();
	private JLabel lblTittel;
	private JLabel lblBeskrivelse;
	private JLabel lblOpprettAvtale;

	private Appointment model;
	private JTextArea txtrBeskrivelse;
	private JSpinner startTime;
	private JSpinner endTime;
	private JXDatePicker startDatePicker;
	private JXDatePicker endDatePicker;

	private JList selectedPeopleJList;
	private JButton okButton;
	private JButton cancelButton;

	SelectedEmployeesListModel selectedEmployeesListModel;

	/**
	 * Launch the application.
	 */
	// public static void main(String[] args) {
	// try {
	// UIManager
	// .setLookAndFeel("org.jvnet.substance.skin.SubstanceOfficeBlue2007LookAndFeel");
	// } catch (Throwable e) {
	// e.printStackTrace();
	// }
	// try {
	// // Person.exampleCurrentUser();
	// Person.makeExamplesUsers();
	// Room.makeExampleRooms();
	// Appointment.makeExamples();
	// NewAppointmentWindow dialog = new NewAppointmentWindow(Appointment
	// .all().get(0));
	// dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
	//
	// } catch (Exception e) {
	// e.printStackTrace();
	// }
	// }

	private void findAppropriateRoom() {
		if (!rdbtnAutomatisk.isSelected()) {
			System.out.println("Automatisk romvalg er ikke p�.");
			return;
		}

		int interns = selectedEmployeesListModel.getSize();
		int externs = Integer.parseInt(txtGuestCount.getText());
		int total = interns + externs;

		System.out.println("Leter etter rom for " + total + " personer");
		Room best = Room.findBestMatch(model, total);

		if (best == null) {
			System.out.println("No good room was found, MF!");
			return;
		}

		roomSelectionBox.setSelectedItem(best);
		roomSelectionBox.repaint();
		System.out.println(((Room) roomSelectionBox.getModel()
				.getSelectedItem()).toString());
	}

	/**
	 * Create the dialog.
	 */
	public NewAppointmentWindow(Appointment model) {
		model.setOwner(Person.getCurrentUser());
		
		addMouseMotionListener(new MouseMotionListener() {

			@Override
			public void mouseMoved(MouseEvent arg0) {
				// TODO Auto-generated method stub

			}

			@Override
			public void mouseDragged(MouseEvent m) {

				// System.out.println("dragged: "+arg0.getLocationOnScreen()+". X:"+arg0.getX()+". Y:"+arg0.getY());
				// setLocale(arg0.getLocationOnScreen());

				setLocation(m.getLocationOnScreen());
				// setLocation(new
				// java.awt.Point(arg0.getLocationOnScreen().x-arg0.getX(),
				// arg0.getLocationOnScreen().y-arg0.getY()));
				// setLocation(arg0.getXOnScreen()-arg0.getX(),
				// arg0.getYOnScreen()-arg0.getY());
			}
		});

		addKeyListener(new KeyListener() {

			@Override
			public void keyTyped(KeyEvent e) {
				// TODO Auto-generated method stub

			}

			@Override
			public void keyReleased(KeyEvent e) {
				// TODO Auto-generated method stub

			}

			@Override
			public void keyPressed(KeyEvent e) {
				if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
					processWindowEvent(new WindowEvent(
							NewAppointmentWindow.this,
							WindowEvent.WINDOW_CLOSING));
				}
			}
		});

		setResizable(false);
		setUndecorated(true);
		setVisible(true);

		this.model = model;

		setBounds(100, 100, 843, 644);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		contentPanel.setLayout(null);
		{
			txtTittel = new JTextField();
			txtTittel.setBounds(57, 114, 187, 22);
			txtTittel.setToolTipText("Tittel");
			contentPanel.add(txtTittel);
			txtTittel.setColumns(10);
		}

		txtrBeskrivelse = new JTextArea();
		txtrBeskrivelse.setLineWrap(true);
		txtrBeskrivelse.setWrapStyleWord(true);
		txtrBeskrivelse.setToolTipText("Beskrivelse");
		txtrBeskrivelse.setBounds(12, 242, 232, 161);
		contentPanel.add(txtrBeskrivelse);

		/*
		 * final JLabel label = new JLabel();
		 * label.setText("Choose Date by selecting below."); label.setBounds(12,
		 * 81, 171, 22); contentPanel.add(label);
		 */
		startDatePicker = new JXDatePicker();
		startDatePicker.setBounds(57, 152, 187, 22);
		contentPanel.add(startDatePicker);

		rdbtnJobb = new JRadioButton("Jobb");
		rdbtnJobb.setBounds(108, 55, 66, 25);
		rdbtnJobb.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				if (rdbtnJobb.isSelected()) {
					lblInterneDeltakere.setEnabled(true);
					lblEksterneDeltakere.setEnabled(true);
					lblVelgInterneDeltagere.setEnabled(true);
					lblVelgRom.setEnabled(true);
					rdbtnAutomatisk.setEnabled(true);
					rdbtnManuell.setEnabled(true);
					lblRom.setEnabled(true);
					if (rdbtnAutomatisk.isSelected()) {
						roomSelectionBox.setEnabled(false);
					} else {
						roomSelectionBox.setEnabled(true);
					}
					searchField.setEnabled(true);
					searchField.setVisible(false);
					employeesJList.setEnabled(true);
					txtGuestCount.setEnabled(true);
				}
			}
		});
		rdbtnJobb.setSelected(true);
		buttonGroup.add(rdbtnJobb);
		contentPanel.add(rdbtnJobb);

		rdbtnPrivat = new JRadioButton("Privat");
		rdbtnPrivat.setBounds(178, 55, 66, 25);
		rdbtnPrivat.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				if (rdbtnPrivat.isSelected()) {
					lblInterneDeltakere.setEnabled(false);
					lblEksterneDeltakere.setEnabled(false);
					lblVelgInterneDeltagere.setEnabled(false);
					lblVelgRom.setEnabled(false);
					rdbtnAutomatisk.setEnabled(false);
					rdbtnManuell.setEnabled(false);
					lblRom.setEnabled(false);
					roomSelectionBox.setEnabled(false);
					searchField.setEnabled(false);
					employeesJList.setEnabled(false);
					txtGuestCount.setEnabled(false);
				}

			}
		});
		buttonGroup.add(rdbtnPrivat);
		contentPanel.add(rdbtnPrivat);
		{
			JLabel lblVelgAvtaletype = new JLabel("Velg avtaletype:");
			lblVelgAvtaletype.setBounds(12, 59, 88, 16);
			contentPanel.add(lblVelgAvtaletype);
		}

		employeesJList = new JEmployeeList();
		employeesJList.setBounds(263, 90, 239, 313);
		contentPanel.add(employeesJList);

		searchField = new JTextField();
		searchField.setVisible(false);
		searchField.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				JOptionPane.showMessageDialog(null, "To be impl");
			}
		});
		searchField.setForeground(Color.GRAY);
		searchField.addFocusListener(new FocusAdapter() {
			@Override
			public void focusLost(FocusEvent arg0) {
				searchField.setText("Search");
			}

			@Override
			public void focusGained(FocusEvent e) {
				searchField.setText("");
			}
		});
		searchField.setBounds(263, 56, 239, 22);
		searchField.setText("Search");
		contentPanel.add(searchField);
		searchField.setColumns(10);

		SpinnerModel spinnerModel = new SpinnerDateModel();
		startTime = new JSpinner(spinnerModel);
		startTime.setBounds(57, 196, 66, 22);

		JComponent jsde_startTime = new JSpinner.DateEditor(startTime, "HH:mm");
		startTime.setEditor(jsde_startTime);
		startTime.setValue(new Date());
		contentPanel.add(startTime);

		JLabel lblStart = new JLabel("Start:");
		lblStart.setBounds(12, 199, 52, 16);
		contentPanel.add(lblStart);

		JLabel lblSlutt = new JLabel("Slutt:");
		lblSlutt.setBounds(135, 199, 39, 16);
		contentPanel.add(lblSlutt);

		SpinnerModel model1 = new SpinnerDateModel();
		endTime = new JSpinner(model1);
		JComponent jsde_endTime = new JSpinner.DateEditor(endTime, "HH:mm");
		endTime.setEditor(jsde_endTime);
		endTime.setValue(new Date());
		endTime.setBounds(178, 196, 66, 22);
		contentPanel.add(endTime);

		txtSted = new JTextField();
		txtSted.setBounds(57, 435, 187, 22);
		contentPanel.add(txtSted);
		txtSted.setColumns(10);

		JLabel lblSted = new JLabel("Sted:");
		lblSted.setBounds(12, 438, 52, 16);
		contentPanel.add(lblSted);

		lblInterneDeltakere = new JLabel("Antall interne deltakere:");
		lblInterneDeltakere.setBounds(263, 438, 150, 16);
		contentPanel.add(lblInterneDeltakere);

		lblEksterneDeltakere = new JLabel("Antall eksterne deltakere:");
		lblEksterneDeltakere.setBounds(263, 476, 150, 16);
		contentPanel.add(lblEksterneDeltakere);

		txtGuestCount = new JTextField();
		txtGuestCount.setBounds(411, 473, 77, 22);
		contentPanel.add(txtGuestCount);
		txtGuestCount.setColumns(10);

		externPeeps = new JTextField();
		externPeeps.setBounds(411, 435, 77, 22);
		externPeeps.setEditable(false);
		contentPanel.add(externPeeps);
		externPeeps.setColumns(10);

		lblVelgRom = new JLabel("Velg rom:");
		lblVelgRom.setBounds(562, 438, 52, 16);
		contentPanel.add(lblVelgRom);

		rdbtnAutomatisk = new JRadioButton("Automatisk");
		rdbtnAutomatisk.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				if (rdbtnAutomatisk.isSelected()) {
					roomSelectionBox.setEnabled(false);
				}
			}
		});
		rdbtnAutomatisk.setBounds(620, 434, 101, 24);
		buttonGroup_1.add(rdbtnAutomatisk);
		rdbtnAutomatisk.setSelected(true);
		contentPanel.add(rdbtnAutomatisk);
		rdbtnManuell = new JRadioButton("Manuell");
		rdbtnManuell.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				if (rdbtnManuell.isSelected()) {
					roomSelectionBox.setEnabled(true);
				}
			}
		});
		rdbtnManuell.setBounds(725, 434, 76, 24);
		buttonGroup_1.add(rdbtnManuell);
		contentPanel.add(rdbtnManuell);

		lblRom = new JLabel("Rom:");
		lblRom.setBounds(562, 476, 52, 16);
		contentPanel.add(lblRom);

		roomSelectionBox = new JComboBox();
		roomSelectionBox.setEnabled(false);
		roomSelectionBox.setModel(new RoomSelectModel(model.getRoom()));
		roomSelectionBox.setRenderer(new RoomListRenderer());
		roomSelectionBox.setBounds(632, 473, 148, 22);
		contentPanel.add(roomSelectionBox);

		lblVelgInterneDeltagere = new JLabel("Ansatte:");
		lblVelgInterneDeltagere.setBounds(263, 18, 150, 16);
		contentPanel.add(lblVelgInterneDeltagere);

		JLabel lblDato = new JLabel("Dato:");
		lblDato.setBounds(12, 155, 52, 16);
		contentPanel.add(lblDato);

		lblTittel = new JLabel("Tittel:");
		lblTittel.setBounds(12, 117, 39, 16);
		contentPanel.add(lblTittel);

		lblBeskrivelse = new JLabel("Beskrivelse:");
		lblBeskrivelse.setBounds(12, 227, 77, 16);
		contentPanel.add(lblBeskrivelse);

		lblOpprettAvtale = new JLabel("Opprett avtale");
		lblOpprettAvtale.setFont(new Font("Segoe UI", Font.BOLD, 16));
		lblOpprettAvtale.setBounds(12, 6, 216, 37);
		contentPanel.add(lblOpprettAvtale);

		selectedPeopleJList = new JList();
		selectedEmployeesListModel = new SelectedEmployeesListModel();
		selectedPeopleJList.setBorder(new LineBorder(Color.WHITE, 1, true));
		selectedPeopleJList.setBounds(562, 90, 239, 314);
		selectedPeopleJList.setModel(selectedEmployeesListModel);
		selectedPeopleJList
				.setCellRenderer(new SelectedPeopleListCellRenderer());
		contentPanel.add(selectedPeopleJList);

		JButton btnLeggTil = new JButton(">");
		btnLeggTil.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				Person p = (Person) employeesJList.getSelectedValue();
				if (p != null) {
					// NewAppointmentWindow.this.model.invite(p);
					selectedEmployeesListModel.addPerson(p);
					externPeeps.setText(selectedEmployeesListModel.getSize()
							+ " stk");
				}
			}
		});
		btnLeggTil.setBounds(513, 206, 37, 23);
		contentPanel.add(btnLeggTil);

		JButton btnFjern = new JButton("<");
		btnFjern.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				int index = selectedPeopleJList.getSelectedIndex();
				if (index >= 0) {
					selectedEmployeesListModel.removePerson(index);
					externPeeps.setText(selectedEmployeesListModel.getSize()
							+ " stk");
				}
			}
		});
		btnFjern.setBounds(513, 240, 37, 23);
		contentPanel.add(btnFjern);

		JLabel lblValgteDeltakere = new JLabel("Valgte deltakere:");
		lblValgteDeltakere.setBounds(562, 19, 150, 14);
		contentPanel.add(lblValgteDeltakere);

		endDatePicker = new JXDatePicker();
		endDatePicker.setVisible(false);
		endDatePicker.setBounds(135, 532, 77, 22);
		contentPanel.add(endDatePicker);

		JLabel lblRoomStatus = new JLabel("Room Status");
		lblRoomStatus.setFont(new Font("Dialog", Font.BOLD, 12));
		lblRoomStatus.setForeground(Color.RED);
		lblRoomStatus.setBounds(631, 507, 149, 16);
		contentPanel.add(lblRoomStatus);
		{
			JPanel buttonPane = new JPanel();
			buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
			{
				okButton = new JButton("OK");
				
				
				
				okButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						Appointment a = NewAppointmentWindow.this
                        .model;
                a.alive = true;
                a.room = roomSelectionBox.getSelectedIndex();
                a.setOwner(Person.getCurrentUser());
                a.updateInviteList(selectedEmployeesListModel.list);
                ClientModelHandler.updateModel(a);
                if (a.isNew()) {
                        a.generateMessages(MessageType.INVITE); 
                }
                else {
                        a.generateMessages(MessageType.MEETING_CHANGED);
                }
                processWindowEvent(new WindowEvent(NewAppointmentWindow.this, 
                                WindowEvent.WINDOW_CLOSING));

						
						
						
//						NewAppointmentWindow.this.model.alive = true;
//						NewAppointmentWindow.this.model.endDate = NewAppointmentWindow.this.model.startDate;
//						NewAppointmentWindow.this.model
//								.updateInviteList(selectedEmployeesListModel.list);
//						ClientModelHandler
//								.updateModel(NewAppointmentWindow.this.model);
//						processWindowEvent(new WindowEvent(
//								NewAppointmentWindow.this,
//								WindowEvent.WINDOW_CLOSING));
					}
				});
				okButton.setActionCommand("OK");
				buttonPane.add(okButton);
				getRootPane().setDefaultButton(okButton);
			}
			{
				cancelButton = new JButton("Avbryt");
				cancelButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent arg0) {
						processWindowEvent(new WindowEvent(
								NewAppointmentWindow.this,
								WindowEvent.WINDOW_CLOSING));
					}
				});
				cancelButton.setActionCommand("Cancel");
				buttonPane.add(cancelButton);
			}
		}
		initDataBindings();
	}
	protected void initDataBindings() {
		BeanProperty<Appointment, String> appointmentBeanProperty = BeanProperty.create("title");
		BeanProperty<JTextField, String> jTextFieldBeanProperty = BeanProperty.create("text");
		AutoBinding<Appointment, String, JTextField, String> autoBinding = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, model, appointmentBeanProperty, txtTittel, jTextFieldBeanProperty, "titleBinding");
		autoBinding.bind();
		//
		BeanProperty<Appointment, String> appointmentBeanProperty_1 = BeanProperty.create("description");
		BeanProperty<JTextArea, String> jTextAreaBeanProperty = BeanProperty.create("text");
		AutoBinding<Appointment, String, JTextArea, String> autoBinding_1 = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, model, appointmentBeanProperty_1, txtrBeskrivelse, jTextAreaBeanProperty);
		autoBinding_1.bind();
		//
		BeanProperty<Appointment, String> appointmentBeanProperty_2 = BeanProperty.create("place");
		BeanProperty<JTextField, String> jTextFieldBeanProperty_1 = BeanProperty.create("text");
		AutoBinding<Appointment, String, JTextField, String> autoBinding_2 = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, model, appointmentBeanProperty_2, txtSted, jTextFieldBeanProperty_1);
		autoBinding_2.bind();
		//
		BeanProperty<Appointment, Integer> appointmentBeanProperty_3 = BeanProperty.create("guestCount");
		BeanProperty<JTextField, String> jTextFieldBeanProperty_2 = BeanProperty.create("text");
		AutoBinding<Appointment, Integer, JTextField, String> autoBinding_3 = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, model, appointmentBeanProperty_3, txtGuestCount, jTextFieldBeanProperty_2);
		autoBinding_3.bind();
		//
		BeanProperty<Appointment, Time> appointmentBeanProperty_4 = BeanProperty.create("start");
		BeanProperty<JSpinner, Object> jSpinnerBeanProperty = BeanProperty.create("value");
		AutoBinding<Appointment, Time, JSpinner, Object> autoBinding_4 = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, model, appointmentBeanProperty_4, startTime, jSpinnerBeanProperty);
		autoBinding_4.setConverter(new TimeConverter());
		autoBinding_4.bind();
		//
		BeanProperty<Appointment, Time> appointmentBeanProperty_5 = BeanProperty.create("end");
		BeanProperty<JSpinner, Object> jSpinnerBeanProperty2 = BeanProperty.create("value");
		AutoBinding<Appointment, Time, JSpinner, Object> autoBinding_5 = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, model, appointmentBeanProperty_5, endTime, jSpinnerBeanProperty2);
		autoBinding_5.setConverter(new TimeConverter());
		autoBinding_5.bind();
		//
		BeanProperty<Appointment, java.sql.Date> appointmentBeanProperty_6 = BeanProperty.create("startDate");
		BeanProperty<JXDatePicker, Date> jXDatePickerBeanProperty_1 = BeanProperty.create("date");
		AutoBinding<Appointment, java.sql.Date, JXDatePicker, Date> autoBinding_6 = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, model, appointmentBeanProperty_6, startDatePicker, jXDatePickerBeanProperty_1);
		autoBinding_6.setConverter(new DateConverter());
		autoBinding_6.bind();
		//
		BeanProperty<Appointment, Room> appointmentBeanProperty_8 = BeanProperty.create("room");
		BeanProperty<JComboBox, Object> jComboBoxBeanProperty = BeanProperty.create("selectedItem");
		AutoBinding<Appointment, Room, JComboBox, Object> autoBinding_8 = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, model, appointmentBeanProperty_8, roomSelectionBox, jComboBoxBeanProperty, "tehroombindingyo");
		autoBinding_8.bind();
		//
		BeanProperty<Appointment, java.sql.Date> appointmentBeanProperty_7 = BeanProperty.create("endDate");
		BeanProperty<JXDatePicker, Date> jXDatePickerBeanProperty_2 = BeanProperty.create("date");
		AutoBinding<Appointment, java.sql.Date, JXDatePicker, Date> autoBinding_7 = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, model, appointmentBeanProperty_7, endDatePicker, jXDatePickerBeanProperty_2);
		autoBinding_7.setConverter(new DateConverter());
		autoBinding_7.bind();
	}
}
